init;

global trans_info m n k

%Load a data stream from an image
pixel_stream = serialize_image('img/tower.jpg');
pixel_stream = pixel_stream(1:floor(end/50));

%Convert the 8-bit pixels into a binary stream
bin_stream = zeros(1,8*length(pixel_stream));
for i = 1 : pixel_stream
    bin_stream(i:i+8) = dec2binvec(pixel_stream(i));
end

clear pixel_stream

%Chunk those 8-bit pixels into m*k-bit sections
pad_needed = mod(length(bin_stream),m*k);
%Zero pad to get an integer number of words
if pad_needed
    bin_stream = [bin_stream zeros(1,pad_needed)];
end

message_polys = zeros(length(bin_stream / m*k),k);
L = length(bin_stream);
h = waitbar(0,'Building message polynomials...');

%Build message polynomials
j = 1;
for i = 1 : m*k : length(bin_stream) - m*k
    message_polys(j,:) = createMsgPoly(bin_stream(i:i + m*k-1));
    j = j + 1;
    waitbar(i / L,h);
end    
close(h);
clear bin_stream

%Build code polynomials
h = waitbar(0, 'Encoding message polynomials...');
code_polys = zeros(size(message_polys,1),n);
for i = 1 : size(message_polys,1)
    waitbar(i/size(message_polys,1),h);
    code_polys(i,:) = RS_encoder(message_polys(i,:));
end






